package com.dineroquegastar.urule.vo;

import com.dineroquegastar.urule.constant.RespEnum;
import lombok.Getter;

/**
 * 公共响应数据封装
 *
 * @author liuhai
 * @date 2021/3/28 3:57 PM
 */
@Getter
public class ResponseVo {

    private String code;
    private String msg;
    private Object data;

    private ResponseVo(RespEnum respEnum, Object data) {
        this(respEnum.getCode(), respEnum.getMsg(), data);
    }

    private ResponseVo(String code, String msg) {
        this(code, msg, null);
    }

    public ResponseVo(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseVo success() {
        return new ResponseVo(RespEnum.SUCCESS, null);
    }

    public static ResponseVo success(Object param) {
        return new ResponseVo(RespEnum.SUCCESS, param);
    }

    public static ResponseVo fail(RespEnum respEnum) {
        return new ResponseVo(respEnum, null);
    }

    public static ResponseVo fail(String code, String msg) {
        return new ResponseVo(code, msg);
    }
}
